package com.netdisk.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Component;

import com.netdisk.dao.impl.CapacityDao;
import com.netdisk.dao.impl.FileSystemDao;
import com.netdisk.entity.Capacity;
import com.netdisk.entity.FileSystem;
import com.netdisk.entity.Log;
import com.netdisk.entity.User;
import com.netdisk.service.Service;

/**
 * 文件系统Service
 * @author chenlong
 *2013-4-13
 */
@Component("fileSystemService")
public class FileSystemService extends Service<FileSystem>{
	
	private FileSystemDao fileSystemDao;
	
	private CapacityDao capacityDao;
	
	@Resource(name="capacityDao")
	public void setCapacityDao(CapacityDao capacityDao) {
		this.capacityDao = capacityDao;
	}

	@Resource(name="fileSystemDao")
	public void setFileSystemDao(FileSystemDao fileSystemDao) {
		this.fileSystemDao = fileSystemDao;
	}

	@Override
	public void save(FileSystem obj, Log log) {
		fileSystemDao.save(obj);
		logDao.save(log);
	}
	
	public void save(FileSystem obj, Capacity capcity, Log log) {
		fileSystemDao.save(obj);
		capacityDao.update(capcity);
		logDao.save(log);
	}

	@Override
	public void update(FileSystem obj, Log log) {
		fileSystemDao.update(obj);
		logDao.save(log);
	}

	@Override
	public void delete(FileSystem obj, Log log) {
		fileSystemDao.delete(obj);
		logDao.save(log);
	}

	@Override
	public List<FileSystem> findAll() {
		return fileSystemDao.findAll();
	}

	@Override
	public FileSystem findById(String id) {
		return fileSystemDao.findById(id);
	}

	@Override
	public List<FileSystem> findByTop(int from, int max) {
		return fileSystemDao.findByTop(from, max);
	}
	
	public boolean existWithFileName(String ownerId, String parentDir, String fileName){
		return fileSystemDao.existWithFileName(ownerId, parentDir, fileName);
	}
	
	public List<FileSystem> findWithOwnerId(String ownerId, String fileName){
		return fileSystemDao.findWithOwnerId(ownerId, fileName);
	}

	public List<FileSystem> findOwnerParentDir(String ownerId, String parentDir){
		return fileSystemDao.findOwnerParentDir(ownerId, parentDir);
	}
	
	public List<FileSystem> findCompanyParentDir(String companyId, String parentDir){
		return fileSystemDao.findCompanyParentDir(companyId, parentDir);
	}
	
	public List<FileSystem> findWithCompanyId(String companyId, String fileName){
		return fileSystemDao.findWithCompanyId(companyId, fileName);
	}
	
	public List<FileSystem> findFileInTrash(String ownerId){
		return fileSystemDao.findFileInTrash(ownerId);
	}
	
}
